package com.cardvalue.sys.mode;

import android.content.Context;

import com.cardvalue.sys.entity.Address;
import com.cardvalue.sys.newnetwork.Config;
import com.cardvalue.sys.tool.Utiltools;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 都是调用微信接口的
 * Created by cardvalue on 2016/4/21.
 */
public class WeixinService {
    private Retrofit retrofit;
    private Context context;
    private Service.GetAddress  addressService;
    public WeixinService(Context context){
        this.context=context;
        retrofit = new Retrofit.Builder()   //new出对象
                .baseUrl(Config.getWeixinIp())  //添加url
                .addConverterFactory(GsonConverterFactory.create()) //利用gson解析
                .build();
    }


    /**
     * 调用地理位置
     * @param address
     */
    public   void   GetAddress(final String address,final AddressCallback callback){
        addressService=retrofit.create(Service.GetAddress.class);
      Call<Address> repos=addressService.attemAddress(address);
        repos.enqueue(new Callback<Address>() {
            @Override
            public void onResponse(Call<Address> call, Response<Address> response) {
                Address  address=response.body();
                Utiltools.printE("code",address.getResultCode()+"ResultCode()");
                Utiltools.printE("code",address.getError()+"Error()");
                Utiltools.printE("code",address.getResultData().get(1).getName()+"ResultData()()");
                Utiltools.printE("code",address.getResultData().get(1).getCity()+"ResultData()()");
                Utiltools.printE("code",address.getResultData().get(1).getDistrict()+"ResultData()()");

            }

            @Override
            public void onFailure(Call<Address> call, Throwable t) {

            }
        });
    }

    public  interface  AddressCallback {
        void success(Address  address);

        void fail(String msg);

        void cancelDialog();
    }

}
